package com.allianz.webapps.controllers;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.allianz.frame.utils.ApplicationContextUtil;
import com.allianz.webapps.https.interfaces.type001.CoverInit;
import com.allianz.webapps.https.interfaces.type001.pojo.User;
import com.allianz.webapps.https.interfaces.util.HttpsUtil;
import com.allianz.webapps.orderspojo.CP;
@Controller
@RequestMapping(value="about")
public class AboutController {
	
	private Logger logger = LoggerFactory.getLogger(getClass());
	@RequestMapping(value="aboutUsInto")
	public String index(HttpServletRequest request,HttpServletResponse response){
		return "views/page/aboutUsInto";
	}
	@RequestMapping(value="initData")
	@ResponseBody
	public Map<String,Object> initData(HttpServletRequest request,HttpServletResponse response) throws Exception{
		HashMap<String,Object> map = new HashMap<String,Object>();
		String cp = request.getParameter("cp");
		JSONObject cpJson = JSONObject.fromObject(cp);
		CP cpObject = (CP) JSONObject.toBean(cpJson,CP.class );
		User u = (User) ApplicationContextUtil.getSession("username");	
		cpObject.getAppBase().setUser(u);
		logger.info(cpObject!=null?cpObject.toString():"cpObject is null");
		String requestLoginParam = CoverInit.requestLoginParam(cpObject);
		logger.info(requestLoginParam);
		String body = HttpsUtil.httpsPost(requestLoginParam);
		JSONObject json = JSONObject.fromObject(body);
		map.put("data", json.get("Body"));
		return map;
		
	}
	
	@RequestMapping(value = "aboutUs")
	public ModelAndView aboutUs(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView mav = new ModelAndView();
		mav.setViewName("views/page/aboutUs");
		return mav;
	}
	
	@RequestMapping(value = "aboutUsFuture")
	public ModelAndView aboutUsFuture(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView mav = new ModelAndView();
		mav.setViewName("views/page/aboutUsFuture");
		return mav;
	}
	
	@RequestMapping(value = "aboutHistory")
	public ModelAndView aboutHistory(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView mav = new ModelAndView();
		mav.setViewName("views/page/aboutHistory");
		return mav;
	}
}